package com.koko.listener;

import com.koko.order.entity.Cart;
import com.koko.order.entity.Order;
import com.koko.properties.RabbitmqProperties;
import com.koko.service.CartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SpringRabbitListener {

    @Autowired
    private CartService cartService;

    @RabbitListener(queues = RabbitmqProperties.PAY_SUCCESS_CART_QUEUE)
    public void listenPaySuccessUserQueue(Order order) {
        log.info("order模块接收到" + RabbitmqProperties.PAY_SUCCESS_CART_QUEUE + "的消息：【" + order + "】");
        // 清空购物车
        cartService.deleteByUserId(order.getUserId());
    }
}
